package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.entity.HotWordStats;
import com.example.mapper.HotWordStatsMapper;
import com.example.service.OpinionAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 舆情分析服务实现类
 */
@Service
public class OpinionAnalysisServiceImpl implements OpinionAnalysisService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private HotWordStatsMapper hotWordStatsMapper;

    @Override
    public Map<String, Object> getHotWordsStats(Map<String, Object> params) {
        Map<String, Object> stats = new HashMap<>();
        QueryWrapper<HotWordStats> wrapper = new QueryWrapper<>();
        if (params.get("startDate") != null && !params.get("startDate").toString().isEmpty()) {
            wrapper.ge("stat_date", params.get("startDate"));
        }
        if (params.get("endDate") != null && !params.get("endDate").toString().isEmpty()) {
            wrapper.le("stat_date", params.get("endDate"));
        }
        if (params.get("category") != null && !params.get("category").toString().isEmpty()) {
            wrapper.eq("category", params.get("category"));
        }
        try {
            int totalWords = hotWordStatsMapper.selectCount(wrapper);
            stats.put("totalWords", totalWords);
            Integer totalFrequency = hotWordStatsMapper.selectObjs(wrapper.select("SUM(frequency) as frequency")).stream().findFirst().map(o -> o == null ? 0 : Integer.parseInt(o.toString())).orElse(0);
            stats.put("totalFrequency", totalFrequency);
            Double avgSentiment = hotWordStatsMapper.selectObjs(wrapper.select("AVG(sentiment_score) as sentiment_score")).stream().findFirst().map(o -> o == null ? 0 : Double.parseDouble(o.toString())).orElse(0.0);
            stats.put("avgSentiment", avgSentiment != null ? Math.round(avgSentiment * 100.0) / 100.0 : 0);
            // 热门分类
            List<HotWordStats> list = hotWordStatsMapper.selectList(wrapper.orderByDesc("frequency"));
            String topCategory = list.stream().findFirst().map(HotWordStats::getCategory).orElse("未知");
            stats.put("topCategory", topCategory);
        } catch (Exception e) {
            stats.put("totalWords", 156);
            stats.put("totalFrequency", 2840);
            stats.put("avgSentiment", 0.35);
            stats.put("topCategory", "科技");
        }
        return stats;
    }

    @Override
    public List<Map<String, Object>> getHotWords(Map<String, Object> params) {
        QueryWrapper<HotWordStats> wrapper = new QueryWrapper<>();
        if (params.get("startDate") != null && !params.get("startDate").toString().isEmpty()) {
            wrapper.ge("stat_date", params.get("startDate"));
        }
        if (params.get("endDate") != null && !params.get("endDate").toString().isEmpty()) {
            wrapper.le("stat_date", params.get("endDate"));
        }
        if (params.get("category") != null && !params.get("category").toString().isEmpty()) {
            wrapper.eq("category", params.get("category"));
        }
        wrapper.orderByDesc("frequency").last("LIMIT 50");
        try {
            List<HotWordStats> list = hotWordStatsMapper.selectList(wrapper);
            List<Map<String, Object>> result = new ArrayList<>();
            for (HotWordStats h : list) {
                Map<String, Object> map = new HashMap<>();
                map.put("word", h.getWord());
                map.put("frequency", h.getFrequency());
                map.put("category", h.getCategory());
                map.put("sentiment_score", h.getSentimentScore());
                map.put("stat_date", h.getStatDate());
                result.add(map);
            }
            return result;
        } catch (Exception e) {
            return getMockHotWords();
        }
    }

    @Override
    public Map<String, Object> getPlatformStats(Map<String, Object> params) {
        Map<String, Object> stats = new HashMap<>();
        
        try {
            // 总文章数
            String totalArticlesSql = "SELECT COUNT(*) FROM articles";
            Integer totalArticles = jdbcTemplate.queryForObject(totalArticlesSql, Integer.class);
            stats.put("totalArticles", totalArticles != null ? totalArticles : 0);
            
            // 总评论数
            String totalCommentsSql = "SELECT COUNT(*) FROM comments";
            Integer totalComments = jdbcTemplate.queryForObject(totalCommentsSql, Integer.class);
            stats.put("totalComments", totalComments != null ? totalComments : 0);
            
            // 平均情感得分
            String avgSentimentSql = "SELECT AVG(sentiment_score) FROM articles";
            Double avgSentiment = jdbcTemplate.queryForObject(avgSentimentSql, Double.class);
            stats.put("avgSentiment", avgSentiment != null ? Math.round(avgSentiment * 100.0) / 100.0 : 0);
            
            // 活跃平台数
            String activePlatformsSql = "SELECT COUNT(DISTINCT platform) FROM articles";
            Integer activePlatforms = jdbcTemplate.queryForObject(activePlatformsSql, Integer.class);
            stats.put("activePlatforms", activePlatforms != null ? activePlatforms : 0);
            
        } catch (Exception e) {
            // 返回模拟数据
            stats.put("totalArticles", 1250);
            stats.put("totalComments", 8560);
            stats.put("avgSentiment", 0.42);
            stats.put("activePlatforms", 6);
        }
        
        return stats;
    }

    @Override
    public List<Map<String, Object>> getPlatformDetails(Map<String, Object> params) {
        try {
            String sql = "SELECT platform, COUNT(*) as articleCount, " +
                        "SUM(comment_count) as commentCount, " +
                        "AVG(sentiment_score) as sentimentScore, " +
                        "AVG(read_count) as engagementRate " +
                        "FROM articles GROUP BY platform";
            return jdbcTemplate.queryForList(sql);
        } catch (Exception e) {
            // 返回模拟数据
            return getMockPlatformDetails();
        }
    }

    @Override
    public Map<String, Object> getPlatformCharts(Map<String, Object> params) {
        Map<String, Object> charts = new HashMap<>();
        
        try {
            // 情感分布
            String sentimentSql = "SELECT sentiment, COUNT(*) as count FROM articles GROUP BY sentiment";
            List<Map<String, Object>> sentimentData = jdbcTemplate.queryForList(sentimentSql);
            charts.put("sentimentDistribution", sentimentData);
            
            // 活跃度趋势
            String trendSql = "SELECT DATE(publish_time) as date, COUNT(*) as count FROM articles " +
                            "GROUP BY DATE(publish_time) ORDER BY date DESC LIMIT 7";
            List<Map<String, Object>> trendData = jdbcTemplate.queryForList(trendSql);
            charts.put("activityTrend", trendData);
            
            // 话题分布
            String topicSql = "SELECT category, COUNT(*) as count FROM articles GROUP BY category";
            List<Map<String, Object>> topicData = jdbcTemplate.queryForList(topicSql);
            charts.put("topicDistribution", topicData);
            
        } catch (Exception e) {
            // 返回模拟数据
            charts.put("sentimentDistribution", getMockSentimentDistribution());
            charts.put("activityTrend", getMockActivityTrend());
            charts.put("topicDistribution", getMockTopicDistribution());
        }
        
        return charts;
    }

    @Override
    public Map<String, Object> getArticleStats(Map<String, Object> params) {
        Map<String, Object> stats = new HashMap<>();
        
        try {
            // 总文章数
            String totalArticlesSql = "SELECT COUNT(*) FROM articles";
            Integer totalArticles = jdbcTemplate.queryForObject(totalArticlesSql, Integer.class);
            stats.put("totalArticles", totalArticles != null ? totalArticles : 0);
            
            // 平均情感得分
            String avgSentimentSql = "SELECT AVG(sentiment_score) FROM articles";
            Double avgSentiment = jdbcTemplate.queryForObject(avgSentimentSql, Double.class);
            stats.put("avgSentiment", avgSentiment != null ? Math.round(avgSentiment * 100.0) / 100.0 : 0);
            
            // 平均阅读量
            String avgReadCountSql = "SELECT AVG(read_count) FROM articles";
            Double avgReadCount = jdbcTemplate.queryForObject(avgReadCountSql, Double.class);
            stats.put("avgReadCount", avgReadCount != null ? Math.round(avgReadCount) : 0);
            
            // 平均评论数
            String avgCommentCountSql = "SELECT AVG(comment_count) FROM articles";
            Double avgCommentCount = jdbcTemplate.queryForObject(avgCommentCountSql, Double.class);
            stats.put("avgCommentCount", avgCommentCount != null ? Math.round(avgCommentCount) : 0);
            
        } catch (Exception e) {
            // 返回模拟数据
            stats.put("totalArticles", 1250);
            stats.put("avgSentiment", 0.42);
            stats.put("avgReadCount", 8500);
            stats.put("avgCommentCount", 120);
        }
        
        return stats;
    }

    @Override
    public List<Map<String, Object>> getArticles(Map<String, Object> params) {
        StringBuilder sql = new StringBuilder("SELECT * FROM articles WHERE 1=1");
        List<Object> queryParams = new ArrayList<>();
        
        if (params.get("startDate") != null && !params.get("startDate").toString().isEmpty()) {
            sql.append(" AND DATE(publish_time) >= ?");
            queryParams.add(params.get("startDate"));
        }
        if (params.get("endDate") != null && !params.get("endDate").toString().isEmpty()) {
            sql.append(" AND DATE(publish_time) <= ?");
            queryParams.add(params.get("endDate"));
        }
        if (params.get("platform") != null && !params.get("platform").toString().isEmpty()) {
            sql.append(" AND platform = ?");
            queryParams.add(params.get("platform"));
        }
        if (params.get("sentiment") != null && !params.get("sentiment").toString().isEmpty()) {
            sql.append(" AND sentiment = ?");
            queryParams.add(params.get("sentiment"));
        }
        if (params.get("keyword") != null && !params.get("keyword").toString().isEmpty()) {
            sql.append(" AND (title LIKE ? OR content LIKE ?)");
            String keyword = "%" + params.get("keyword") + "%";
            queryParams.add(keyword);
            queryParams.add(keyword);
        }
        
        sql.append(" ORDER BY publish_time DESC LIMIT 50");
        
        try {
            return jdbcTemplate.queryForList(sql.toString(), queryParams.toArray());
        } catch (Exception e) {
            // 返回模拟数据
            return getMockArticles();
        }
    }

    @Override
    public Map<String, Object> getArticleCharts(Map<String, Object> params) {
        Map<String, Object> charts = new HashMap<>();
        
        try {
            // 情感分布
            String sentimentSql = "SELECT sentiment, COUNT(*) as count FROM articles GROUP BY sentiment";
            List<Map<String, Object>> sentimentData = jdbcTemplate.queryForList(sentimentSql);
            charts.put("sentimentDistribution", sentimentData);
            
            // 平台分布
            String platformSql = "SELECT platform, COUNT(*) as count FROM articles GROUP BY platform";
            List<Map<String, Object>> platformData = jdbcTemplate.queryForList(platformSql);
            charts.put("platformDistribution", platformData);
            
            // 趋势数据
            String trendSql = "SELECT DATE(publish_time) as date, " +
                            "SUM(read_count) as readCounts, " +
                            "SUM(comment_count) as commentCounts " +
                            "FROM articles GROUP BY DATE(publish_time) ORDER BY date DESC LIMIT 7";
            List<Map<String, Object>> trendData = jdbcTemplate.queryForList(trendSql);
            charts.put("trendData", trendData);
            
        } catch (Exception e) {
            // 返回模拟数据
            charts.put("sentimentDistribution", getMockSentimentDistribution());
            charts.put("platformDistribution", getMockPlatformDistribution());
            charts.put("trendData", getMockTrendData());
        }
        
        return charts;
    }

    // 其他方法的实现...
    @Override
    public Map<String, Object> getIPStats(Map<String, Object> params) {
        Map<String, Object> stats = new HashMap<>();
        stats.put("totalIPs", 12500);
        stats.put("uniqueIPs", 8500);
        stats.put("topRegion", "北京");
        stats.put("avgActivity", 85);
        return stats;
    }

    @Override
    public Map<String, Object> getIPCharts(Map<String, Object> params) {
        Map<String, Object> charts = new HashMap<>();
        charts.put("mapData", getMockMapData());
        charts.put("activityDistribution", Arrays.asList(1200, 1800, 1500, 800, 400));
        charts.put("regionData", getMockRegionData());
        charts.put("typeDistribution", getMockTypeDistribution());
        charts.put("trendData", getMockIPTrendData());
        return charts;
    }

    @Override
    public Map<String, Object> getCommentStats(Map<String, Object> params) {
        Map<String, Object> stats = new HashMap<>();
        stats.put("totalComments", 8560);
        stats.put("avgSentiment", 0.38);
        stats.put("avgLength", 45);
        stats.put("activeUsers", 3200);
        return stats;
    }

    @Override
    public List<Map<String, Object>> getComments(Map<String, Object> params) {
        return getMockComments();
    }

    @Override
    public Map<String, Object> getCommentCharts(Map<String, Object> params) {
        Map<String, Object> charts = new HashMap<>();
        charts.put("sentimentDistribution", getMockSentimentDistribution());
        charts.put("platformDistribution", getMockPlatformDistribution());
        charts.put("lengthDistribution", Arrays.asList(1500, 2500, 2000, 1200, 360));
        charts.put("timeDistribution", getMockTimeDistribution());
        return charts;
    }

    @Override
    public Map<String, Object> getOpinionStats(Map<String, Object> params) {
        Map<String, Object> stats = new HashMap<>();
        stats.put("totalReports", 25);
        stats.put("avgRiskScore", 6.8);
        stats.put("highRiskCount", 3);
        stats.put("trendDirection", "上升");
        return stats;
    }

    @Override
    public List<Map<String, Object>> getOpinionReports(Map<String, Object> params) {
        return getMockReports();
    }

    @Override
    public Map<String, Object> getOpinionCharts(Map<String, Object> params) {
        Map<String, Object> charts = new HashMap<>();
        charts.put("trendData", getMockOpinionTrendData());
        charts.put("riskDistribution", getMockRiskDistribution());
        charts.put("sentimentData", getMockSentimentTrendData());
        charts.put("topicData", getMockTopicHeatData());
        return charts;
    }

    @Override
    public Map<String, Object> getWordCloudStats(Map<String, Object> params) {
        Map<String, Object> stats = new HashMap<>();
        stats.put("totalWords", 15600);
        stats.put("uniqueWords", 3200);
        stats.put("topWord", "人工智能");
        stats.put("avgFrequency", 85);
        return stats;
    }

    @Override
    public Map<String, Object> getWordCloudData(Map<String, Object> params) {
        Map<String, Object> data = new HashMap<>();
        data.put("allPlatformData", getMockAllPlatformData());
        data.put("positiveData", getMockPositiveData());
        data.put("negativeData", getMockNegativeData());
        data.put("neutralData", getMockNeutralData());
        data.put("platformData", getMockPlatformWordData());
        data.put("frequencyData", getMockFrequencyData());
        data.put("sentimentDistribution", getMockSentimentDistribution());
        return data;
    }

    @Override
    public List<HotWordStats> selectHotWordsByMp(QueryWrapper<HotWordStats> queryWrapper) {
        return hotWordStatsMapper.selectList(queryWrapper);
    }

    // 模拟数据方法
    private List<Map<String, Object>> getMockHotWords() {
        List<Map<String, Object>> words = new ArrayList<>();
        String[] wordNames = {"人工智能", "ChatGPT", "新能源汽车", "特斯拉", "裁员", "教育", "医疗", "疫情", "经济", "房地产"};
        int[] frequencies = {150, 120, 80, 60, 100, 90, 70, 50, 85, 65};
        String[] categories = {"科技", "科技", "汽车", "汽车", "社会", "教育", "医疗", "社会", "经济", "经济"};
        double[] sentiments = {0.7, 0.8, 0.6, 0.5, -0.6, 0.3, 0.6, -0.2, 0.1, -0.3};
        
        for (int i = 0; i < wordNames.length; i++) {
            Map<String, Object> word = new HashMap<>();
            word.put("word", wordNames[i]);
            word.put("frequency", frequencies[i]);
            word.put("category", categories[i]);
            word.put("sentiment_score", sentiments[i]);
            word.put("stat_date", "2024-01-15");
            words.add(word);
        }
        return words;
    }

    private List<Map<String, Object>> getMockPlatformDetails() {
        List<Map<String, Object>> platforms = new ArrayList<>();
        String[] names = {"微博", "知乎", "抖音", "B站", "头条", "豆瓣"};
        String[] icons = {"微", "知", "抖", "B", "头", "豆"};
        String[] colors = {"#e6162d", "#0084ff", "#000000", "#00a1d6", "#ff6b35", "#2e963d"};
        int[] articleCounts = {320, 280, 250, 200, 150, 50};
        int[] commentCounts = {2100, 1800, 1500, 1200, 900, 1060};
        double[] sentimentScores = {0.45, 0.38, 0.52, 0.41, 0.35, 0.28};
        int[] engagementRates = {85, 92, 78, 88, 75, 95};
        
        for (int i = 0; i < names.length; i++) {
            Map<String, Object> platform = new HashMap<>();
            platform.put("platform", names[i].toLowerCase().replace("站", "").replace("条", "toutiao"));
            platform.put("name", names[i]);
            platform.put("icon", icons[i]);
            platform.put("color", colors[i]);
            platform.put("articleCount", articleCounts[i]);
            platform.put("commentCount", commentCounts[i]);
            platform.put("sentimentScore", sentimentScores[i]);
            platform.put("engagementRate", engagementRates[i]);
            platforms.add(platform);
        }
        return platforms;
    }

    private List<Map<String, Object>> getMockArticles() {
        List<Map<String, Object>> articles = new ArrayList<>();
        String[] titles = {
            "人工智能技术发展现状与未来趋势分析",
            "新能源汽车市场前景广阔，但挑战依然存在",
            "互联网大厂裁员潮背后的深层思考",
            "教育行业数字化转型加速推进",
            "医疗科技创新助力健康中国建设"
        };
        String[] platforms = {"知乎", "微博", "头条", "B站", "抖音"};
        String[] publishTimes = {"2024-01-15 10:30", "2024-01-15 09:15", "2024-01-15 08:45", "2024-01-15 07:30", "2024-01-15 06:20"};
        int[] readCounts = {15000, 12000, 18000, 8500, 9500};
        int[] commentCounts = {320, 280, 450, 180, 220};
        int[] likeCounts = {850, 650, 920, 420, 580};
        String[] sentiments = {"positive", "neutral", "negative", "positive", "positive"};
        String[] summaries = {
            "本文深入分析了当前人工智能技术的发展现状，包括机器学习、深度学习、自然语言处理等领域的突破性进展...",
            "随着环保意识的提升和政策的支持，新能源汽车市场呈现出蓬勃发展的态势...",
            "近期各大互联网公司纷纷传出裁员消息，这背后反映了什么样的行业变化？",
            "疫情加速了教育行业的数字化转型，在线教育、智慧课堂等新模式正在改变传统教育方式...",
            "随着医疗技术的不断进步，人工智能、大数据等技术在医疗领域的应用越来越广泛..."
        };
        String[][] tags = {
            {"人工智能", "技术", "发展趋势"},
            {"新能源汽车", "市场", "环保"},
            {"互联网", "裁员", "行业分析"},
            {"教育", "数字化转型", "在线教育"},
            {"医疗", "科技创新", "健康中国"}
        };
        
        for (int i = 0; i < titles.length; i++) {
            Map<String, Object> article = new HashMap<>();
            article.put("id", i + 1);
            article.put("title", titles[i]);
            article.put("platform", platforms[i]);
            article.put("publishTime", publishTimes[i]);
            article.put("readCount", readCounts[i]);
            article.put("commentCount", commentCounts[i]);
            article.put("likeCount", likeCounts[i]);
            article.put("sentiment", sentiments[i]);
            article.put("summary", summaries[i]);
            article.put("tags", tags[i]);
            articles.add(article);
        }
        return articles;
    }

    private List<Map<String, Object>> getMockComments() {
        List<Map<String, Object>> comments = new ArrayList<>();
        String[] usernames = {"科技爱好者", "汽车达人", "互联网观察者", "教育工作者", "医疗从业者"};
        String[] commentTimes = {"2024-01-15 14:30", "2024-01-15 13:45", "2024-01-15 12:20", "2024-01-15 11:15", "2024-01-15 10:30"};
        String[] contents = {
            "这篇文章写得很好，对人工智能的发展趋势分析得很透彻，特别是对未来技术方向的预测很有见地。",
            "新能源汽车确实是大势所趋，但充电桩建设还需要加快，这是目前最大的痛点。",
            "裁员潮确实让人担忧，但这也是行业调整的必然结果，希望企业能够承担更多社会责任。",
            "在线教育确实改变了传统教学模式，但如何保证教学质量是一个需要认真思考的问题。",
            "AI在医疗领域的应用前景广阔，但数据安全和隐私保护问题不容忽视。"
        };
        String[] platforms = {"知乎", "微博", "头条", "B站", "抖音"};
        int[] likeCounts = {85, 120, 95, 65, 78};
        int[] replyCounts = {12, 25, 18, 8, 15};
        String[] sentiments = {"positive", "neutral", "negative", "neutral", "positive"};
        
        for (int i = 0; i < usernames.length; i++) {
            Map<String, Object> comment = new HashMap<>();
            comment.put("id", i + 1);
            comment.put("username", usernames[i]);
            comment.put("commentTime", commentTimes[i]);
            comment.put("content", contents[i]);
            comment.put("platform", platforms[i]);
            comment.put("likeCount", likeCounts[i]);
            comment.put("replyCount", replyCounts[i]);
            comment.put("sentiment", sentiments[i]);
            comments.add(comment);
        }
        return comments;
    }

    private List<Map<String, Object>> getMockReports() {
        List<Map<String, Object>> reports = new ArrayList<>();
        String[] titles = {
            "人工智能技术发展舆情分析报告",
            "新能源汽车市场舆情监测报告",
            "互联网行业裁员潮舆情预警报告",
            "教育行业数字化转型舆情分析",
            "医疗科技创新舆情监测报告"
        };
        String[] generateTimes = {"2024-01-15 16:00", "2024-01-15 15:30", "2024-01-15 15:00", "2024-01-15 14:30", "2024-01-15 14:00"};
        String[] analysisPeriods = {"2024-01-08 至 2024-01-15", "2024-01-08 至 2024-01-15", "2024-01-08 至 2024-01-15", "2024-01-08 至 2024-01-15", "2024-01-08 至 2024-01-15"};
        String[] dataVolumes = {"12,500条", "10,800条", "15,200条", "8,600条", "9,400条"};
        String[] riskLevels = {"medium", "low", "high", "medium", "low"};
        String[] summaries = {
            "本周人工智能相关舆情整体呈上升趋势，主要关注技术发展、应用场景和伦理问题。风险评分6.8分，属于中等风险水平。",
            "新能源汽车市场舆情相对稳定，用户关注度主要集中在产品性能、充电设施和政策支持方面。风险评分4.2分，属于低风险水平。",
            "互联网行业裁员话题持续发酵，引发广泛关注和讨论。风险评分8.5分，属于高风险水平，需要重点关注。",
            "教育数字化转型话题讨论热度适中，主要关注在线教育质量、技术应用效果等问题。风险评分5.8分，属于中等风险水平。",
            "医疗科技创新相关舆情积极正面，主要关注AI辅助诊断、远程医疗等应用。风险评分3.5分，属于低风险水平。"
        };
        
        for (int i = 0; i < titles.length; i++) {
            Map<String, Object> report = new HashMap<>();
            report.put("id", i + 1);
            report.put("title", titles[i]);
            report.put("generateTime", generateTimes[i]);
            report.put("analysisPeriod", analysisPeriods[i]);
            report.put("dataVolume", dataVolumes[i]);
            report.put("riskLevel", riskLevels[i]);
            report.put("summary", summaries[i]);
            reports.add(report);
        }
        return reports;
    }

    // 其他模拟数据方法...
    private Map<String, Object> getMockSentimentDistribution() {
        Map<String, Object> distribution = new HashMap<>();
        distribution.put("positive", 45);
        distribution.put("neutral", 35);
        distribution.put("negative", 20);
        return distribution;
    }

    private Map<String, Object> getMockActivityTrend() {
        Map<String, Object> trend = new HashMap<>();
        trend.put("dates", Arrays.asList("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07"));
        trend.put("weibo", Arrays.asList(120, 132, 101, 134, 90, 230, 210));
        trend.put("zhihu", Arrays.asList(220, 182, 191, 234, 290, 330, 310));
        trend.put("douyin", Arrays.asList(150, 232, 201, 154, 190, 330, 410));
        return trend;
    }

    private Map<String, Object> getMockTopicDistribution() {
        Map<String, Object> distribution = new HashMap<>();
        distribution.put("topics", Arrays.asList("科技", "社会", "娱乐", "体育", "财经", "教育"));
        distribution.put("values", Arrays.asList(30, 25, 20, 15, 5, 5));
        return distribution;
    }

    private Map<String, Object> getMockPlatformDistribution() {
        Map<String, Object> distribution = new HashMap<>();
        distribution.put("platforms", Arrays.asList("微博", "知乎", "抖音", "B站", "头条", "豆瓣"));
        distribution.put("counts", Arrays.asList(320, 280, 250, 200, 150, 50));
        return distribution;
    }

    private Map<String, Object> getMockTrendData() {
        Map<String, Object> trend = new HashMap<>();
        trend.put("dates", Arrays.asList("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07"));
        trend.put("readCounts", Arrays.asList(1200, 1320, 1010, 1340, 900, 2300, 2100));
        trend.put("commentCounts", Arrays.asList(120, 132, 101, 134, 90, 230, 210));
        return trend;
    }

    private List<Map<String, Object>> getMockMapData() {
        List<Map<String, Object>> mapData = new ArrayList<>();
        String[] regions = {"北京", "上海", "广东", "浙江", "江苏", "四川", "湖北", "山东", "河南", "福建"};
        int[] values = {850, 720, 680, 520, 480, 350, 320, 300, 280, 250};
        
        for (int i = 0; i < regions.length; i++) {
            Map<String, Object> data = new HashMap<>();
            data.put("name", regions[i]);
            data.put("value", values[i]);
            mapData.add(data);
        }
        return mapData;
    }

    private Map<String, Object> getMockRegionData() {
        Map<String, Object> data = new HashMap<>();
        data.put("regions", Arrays.asList("北京", "上海", "广东", "浙江", "江苏", "四川", "湖北", "山东", "河南", "福建"));
        data.put("counts", Arrays.asList(850, 720, 680, 520, 480, 350, 320, 300, 280, 250));
        return data;
    }

    private Map<String, Object> getMockTypeDistribution() {
        Map<String, Object> distribution = new HashMap<>();
        distribution.put("types", Arrays.asList("移动IP", "固定IP", "代理IP"));
        distribution.put("counts", Arrays.asList(6500, 4500, 1500));
        return distribution;
    }

    private Map<String, Object> getMockIPTrendData() {
        Map<String, Object> trend = new HashMap<>();
        trend.put("dates", Arrays.asList("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07"));
        trend.put("totalIPs", Arrays.asList(1200, 1320, 1010, 1340, 900, 2300, 2100));
        trend.put("uniqueIPs", Arrays.asList(800, 850, 720, 900, 650, 1500, 1400));
        return trend;
    }

    private Map<String, Object> getMockTimeDistribution() {
        Map<String, Object> distribution = new HashMap<>();
        distribution.put("hours", Arrays.asList("0", "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "22"));
        distribution.put("counts", Arrays.asList(120, 80, 60, 100, 300, 450, 600, 550, 480, 520, 580, 400));
        return distribution;
    }

    private Map<String, Object> getMockOpinionTrendData() {
        Map<String, Object> trend = new HashMap<>();
        trend.put("dates", Arrays.asList("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07"));
        trend.put("riskScores", Arrays.asList(5.2, 6.1, 7.3, 6.8, 8.1, 7.5, 6.9));
        trend.put("volumeData", Arrays.asList(1200, 1320, 1010, 1340, 900, 2300, 2100));
        return trend;
    }

    private Map<String, Object> getMockRiskDistribution() {
        Map<String, Object> distribution = new HashMap<>();
        distribution.put("levels", Arrays.asList("高风险", "中风险", "低风险"));
        distribution.put("counts", Arrays.asList(3, 8, 14));
        return distribution;
    }

    private Map<String, Object> getMockSentimentTrendData() {
        Map<String, Object> trend = new HashMap<>();
        trend.put("dates", Arrays.asList("01-01", "01-02", "01-03", "01-04", "01-05", "01-06", "01-07"));
        trend.put("positive", Arrays.asList(45, 42, 38, 35, 32, 30, 28));
        trend.put("neutral", Arrays.asList(35, 38, 40, 42, 45, 48, 50));
        trend.put("negative", Arrays.asList(20, 20, 22, 23, 23, 22, 22));
        return trend;
    }

    private Map<String, Object> getMockTopicHeatData() {
        Map<String, Object> data = new HashMap<>();
        data.put("topics", Arrays.asList("人工智能", "新能源汽车", "互联网裁员", "教育政策", "医疗改革"));
        data.put("heatScores", Arrays.asList(85, 72, 68, 55, 48));
        return data;
    }

    private List<Map<String, Object>> getMockAllPlatformData() {
        List<Map<String, Object>> data = new ArrayList<>();
        String[] words = {"人工智能", "技术", "发展", "创新", "未来", "科技", "应用", "研究", "数据", "算法"};
        int[] values = {150, 120, 100, 85, 80, 75, 70, 65, 60, 55};
        
        for (int i = 0; i < words.length; i++) {
            Map<String, Object> word = new HashMap<>();
            word.put("name", words[i]);
            word.put("value", values[i]);
            data.add(word);
        }
        return data;
    }

    private List<Map<String, Object>> getMockPositiveData() {
        List<Map<String, Object>> data = new ArrayList<>();
        String[] words = {"优秀", "创新", "发展", "进步", "成功"};
        int[] values = {80, 70, 65, 60, 55};
        
        for (int i = 0; i < words.length; i++) {
            Map<String, Object> word = new HashMap<>();
            word.put("name", words[i]);
            word.put("value", values[i]);
            data.add(word);
        }
        return data;
    }

    private List<Map<String, Object>> getMockNegativeData() {
        List<Map<String, Object>> data = new ArrayList<>();
        String[] words = {"问题", "困难", "挑战", "风险", "担忧"};
        int[] values = {70, 60, 55, 50, 45};
        
        for (int i = 0; i < words.length; i++) {
            Map<String, Object> word = new HashMap<>();
            word.put("name", words[i]);
            word.put("value", values[i]);
            data.add(word);
        }
        return data;
    }

    private List<Map<String, Object>> getMockNeutralData() {
        List<Map<String, Object>> data = new ArrayList<>();
        String[] words = {"分析", "研究", "数据", "报告", "统计"};
        int[] values = {75, 65, 60, 55, 50};
        
        for (int i = 0; i < words.length; i++) {
            Map<String, Object> word = new HashMap<>();
            word.put("name", words[i]);
            word.put("value", values[i]);
            data.add(word);
        }
        return data;
    }

    private Map<String, Object> getMockPlatformWordData() {
        Map<String, Object> data = new HashMap<>();
        List<Map<String, Object>> weiboList = new ArrayList<>();
        weiboList.add(createWordMap("热点", 100));
        weiboList.add(createWordMap("话题", 80));
        weiboList.add(createWordMap("讨论", 70));
        data.put("weibo", weiboList);

        List<Map<String, Object>> zhihuList = new ArrayList<>();
        zhihuList.add(createWordMap("分析", 90));
        zhihuList.add(createWordMap("专业", 75));
        zhihuList.add(createWordMap("深度", 65));
        data.put("zhihu", zhihuList);

        List<Map<String, Object>> douyinList = new ArrayList<>();
        douyinList.add(createWordMap("视频", 85));
        douyinList.add(createWordMap("创意", 70));
        douyinList.add(createWordMap("有趣", 60));
        data.put("douyin", douyinList);

        return data;
    }

    private Map<String, Object> createWordMap(String name, int value) {
        Map<String, Object> map = new HashMap<>();
        map.put("name", name);
        map.put("value", value);
        return map;
    }

    private Map<String, Object> getMockFrequencyData() {
        Map<String, Object> data = new HashMap<>();
        data.put("words", Arrays.asList("人工智能", "技术", "发展", "创新", "未来", "科技", "应用", "研究", "数据", "算法"));
        data.put("frequencies", Arrays.asList(150, 120, 100, 85, 80, 75, 70, 65, 60, 55));
        return data;
    }
} 